import os, sys
# sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
sys.path.append('./insightface/deploy')
sys.path.append('./insightface/src/common')


from imutils import paths
import face_preprocess
import onnx_if as inf
import cv2
import numpy as np

vis_thres=0.6
print("hello")

img_raw = cv2.imread('./img/hz.jpg')
bboxes = inf.onnx_inference(img_raw)
if len(bboxes) != 0:
    for bboxe in bboxes:
        if bboxe[4] < vis_thres:
            continue
        print(len(bboxe))
        bbox = np.array([bboxe[0], bboxe[1], bboxe[0]+bboxe[2], bboxe[1]+bboxe[3]])
        landmarks = np.array([bboxe[5], bboxe[7], bboxe[9], bboxe[11], bboxe[13],bboxe[6], bboxe[8], bboxe[10], bboxe[12], bboxe[14]])
        landmarks = landmarks.reshape((2,5)).T
        nimg = face_preprocess.preprocess(img_raw, bbox, landmarks, image_size='112,112')
        nimg = cv2.cvtColor(nimg, cv2.COLOR_BGR2RGB)
        cv2.imwrite("huangzhe.jpg", nimg)
